package st.business.tepth.business.goodsorder;

import java.util.List;

import st.business.tepth.base.OnDataConvertListener;
import st.business.tepth.business.bean.MaterialHadApplyBean;

/**
 * Author: shadow
 * Email:  1025431817@qq.com
 * Time:   2019-02-22 17:30
 */

public class GoodsOrderPresenter extends GoodsOrderContract.Presenter {
    private final GoodsOrderContract.View mView;
    private final GoodsOrderContract.Model mModel;

    public GoodsOrderPresenter(GoodsOrderContract.View view) {
        mView = view;
        mModel = new GoodsOrderModel();
    }

    @Override
    void getData(String token,int repairId) {
        addDisposable(mModel.getData(token,repairId,
                new OnDataConvertListener<List<MaterialHadApplyBean>>() {
                    @Override
                    public void convert(List<MaterialHadApplyBean> list) {
                        if (mView != null) {
                            mView.showData(list);
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showData(null);
                        }
                    }
                }));
    }

    @Override
    void returnGoods(String token, String materialApplyList) {
        addDisposable(mModel.returnGoods(token, materialApplyList,
                new OnDataConvertListener<String>() {
                    @Override
                    public void convert(String s) {
                        if (mView != null) {
                            mView.showSucceed("退料成功");
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showError(msg);
                        }
                    }
                },
                new OnDataConvertListener<List<MaterialHadApplyBean>>() {
                    @Override
                    public void convert(List<MaterialHadApplyBean> list) {
                        if (mView != null) {
                            mView.showData(list);
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showError(msg);
                        }
                    }
                }));
    }

    @Override
    void cancelOrder(String token, String items, int status) {
        addDisposable(mModel.cancelOrder(token, items, status,
                new OnDataConvertListener<String>() {
                    @Override
                    public void convert(String s) {
                        if (mView != null) {
                            mView.showSucceed("取消成功");
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showError(msg);
                        }
                    }
                },
                new OnDataConvertListener<List<MaterialHadApplyBean>>() {
                    @Override
                    public void convert(List<MaterialHadApplyBean> list) {
                        if (mView != null) {
                            mView.showData(list);
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showError(msg);
                        }
                    }
                }));
    }

    @Override
    void reApplyOrder(String token, String items, int status) {
        addDisposable(mModel.reApplyOrder(token, items, status,
                new OnDataConvertListener<String>() {
                    @Override
                    public void convert(String s) {
                        if (mView != null) {
                            mView.showSucceed("申请成功");
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showError(msg);
                        }
                    }
                },
                new OnDataConvertListener<List<MaterialHadApplyBean>>() {
                    @Override
                    public void convert(List<MaterialHadApplyBean> list) {
                        if (mView != null) {
                            mView.showData(list);
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showError(msg);
                        }
                    }
                }));
    }
}
